package org.yefei.homeworkday26;

import java.io.*;
import java.util.*;

public class Two {
	// 2：输入一个文件名，输出最后10个字节（提示，RandomAccessFile类）
	public void getLastTen(String name) {
		RandomAccessFile ran = null;
		File file = new File("F:\\Java课件\\Java高级特性ppt\\homework\\第七章", name);
		try {
			ran = new RandomAccessFile(file, "rw");
			ran.seek(ran.length() - 10);
			byte[] b = new byte[10];
			int len = ran.read(b);
			System.out.println(new String(b, 0, len));
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (ran != null) {
				try {
					ran.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入文件名：");
		String name = in.next();
		Two two = new Two();
		two.getLastTen(name);
	}
}
